namespace Maple.Branch.Identity
{
    using Branch.Permissions;
    using Branch.Permissions.Options;
    using PermissionProviders;
    using Volo.Abp.Authorization.Permissions;
    using Volo.Abp.Modularity;

    [DependsOn(typeof(PermissionsDomainModule),
        typeof(IdentityDomainModule))]
    public class IdentityPermissionProviderModule : AbpModule
    {
        public override void ConfigureServices(ServiceConfigurationContext context)
        {
            Configure<PermissionProviderOptions>(options =>
            {
                options.ManagementProviders.Add<UserPermissionProvider>();
                options.ManagementProviders.Add<RolePermissionProvider>();

                //TODO: Can we prevent duplication of permission names without breaking the design and making the system complicated
                options.ProviderPolicies[UserPermissionValueProvider.ProviderName] = "Identity.Users.ManagePermissions";

                options.ProviderPolicies[RolePermissionValueProvider.ProviderName] = "Identity.Roles.ManagePermissions";
            });
        }
    }
}
